<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$live_roomid=intval($_RQ['id']);
	if($live_roomid){
		$this->session('live_roomid',$live_roomid);
	}
}
$live_id=$this->session('live_id');
$live_roomid=$this->session('live_roomid');
$room=pdo_get('core_account_wxapp_live_rooms',array('uniacid'=>$_SESSION['uniacid'],'id'=>$live_roomid));
$tabs=array(
	array('action'=>'/activity.live.index/rooms','title'=>'返回直播间列表'),
	array('op'=>'list','title'=>$room['title'].'-奖励列表'),
);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'roomid'=>$room['roomid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if($_RQ['mid']){
		$params['mid']=$_RQ['mid'];
		$return['params']['mid']=$_RQ['mid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['psize']){
		$return['params']['psize']=$_RQ['psize'];
	}
	$psize = $_RQ['psize']?:20;
	$total='';
	$list=pdo_getslice('core_account_wxapp_live_getlog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		$goods_ids=array();
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$fromuser=pdo_getcolumn('core_account_wxapp_live_looklog',array('mid'=>$item['mid'],'live_roomid'=>$item['live_roomid'],'uniacid'=>$_SESSION['uniacid']),'fromuser');
			$item['fromuser']=cfc('core')->member_show($fromuser);
			$item['goodstitle']=pdo_getcolumn('core_account_wxapp_live_goods',array('id'=>$item['livegoodsid'],'uniacid'=>$_SESSION['uniacid']),'title');
			$item['roomtitle']=pdo_getcolumn('core_account_wxapp_live_rooms',array('id'=>$item['live_roomid'],'uniacid'=>$_SESSION['uniacid']),'name');
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list',
			'edit_op'=>'edit','edit'=>false,'delall'=>false,'del_op'=>'del','total'=>$total,'psize'=>$psize,'list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'fromuser','title'=>'分享人','type'=>'member'),
			array('type'=>'string','title'=>'活动名称','name'=>'goodstitle'),
			array('type'=>'string','title'=>'直播间','name'=>'roomtitle'),
			array('type'=>'string','title'=>'奖励阶梯','name'=>'getfen'),
			array('type'=>'string','title'=>'奖励积分','name'=>'fee'),
			array('type'=>'time','title'=>'时间','name'=>'createtime'),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>18,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		)
	);
	$return['htmls']=$htmls;
	$return['huo_type']=array('看直播奖励积分');
	$return['status']=array('未发布','审核中','已审核','审核不通过');
	exi($return);
}
if($_RQ['op']=='export'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'roomid'=>$room['roomid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if($_RQ['mid']){
		$params['mid']=$_RQ['mid'];
		$return['params']['mid']=$_RQ['mid'];
	}
	if($_RQ['fromuser']){
		$params['fromuser']=$_RQ['fromuser'];
		$return['params']['fromuser']=$_RQ['fromuser'];
	}
	$list=pdo_getall('core_account_wxapp_live_looklog',$params);
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['nickname']=$item['member']['nickname'];
			$fromuser=pdo_getcolumn('core_account_wxapp_live_looklog',array('mid'=>$item['mid'],'live_roomid'=>$item['live_roomid'],'uniacid'=>$_SESSION['uniacid']),'fromuser');
			$item['fromuser']=cfc('core')->member_show($fromuser);
			$item['fnickname']=$item['fromuser']['nickname'];
			$item['goodstitle']=pdo_getcolumn('core_account_wxapp_live_goods',array('id'=>$item['livegoodsid'],'uniacid'=>$_SESSION['uniacid']),'title');
			$item['roomtitle']=pdo_getcolumn('core_account_wxapp_live_rooms',array('id'=>$item['live_roomid'],'uniacid'=>$_SESSION['uniacid']),'name');
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
		}
	}
	$header=array(
		'mid'=>'会员ID',
		'nickname'=>'会员昵称',
		'fnickname'=>'分享人',
		'goodstitle'=>'活动名称',
		'roomtitle'=>'直播间',
		'getfen'=>'奖励阶梯',
		'fee'=>'奖励积分',
		'createtime'=>'时间',
	);
	model('core/tools')->export2excel($header,$list,'奖励数据');
}
if($_RQ['op']=='del'){
	exi('暂时不支持删除！','error');
	exi('删除成功！');
}